package com.jd.cmdb.tsc.service;

import com.jd.cmdb.tsc.dao.TaskDao;
import com.jd.cmdb.tsc.entity.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by tianzhengguo on 2016/1/11.
 */
@Service("taskService")
public class TaskServiceImpl implements TaskService<Task> {
    private static final Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);

    @Resource
    private TaskDao taskDao;

    public List<Task> selAllTasks() throws Exception {
        List<Task> tasks = taskDao.selAllTasks();
        return tasks;
    }

    @Override
    public List<Task> selAllSendingTasks() throws Exception {
        short[] states = {STATE_READY,STATE_WORKER_INNER_FAIL,STATE_SUCCESS};
        return taskDao.selAllTasks(states);
    }

    @Override
    public List<Task> selTasksByStates(short[] states) throws Exception {
        return taskDao.selAllTasks(states);
    }

    @Override
    public List<Task> selTasksByState(short state) throws Exception {
        return taskDao.selTasksByState(state);
    }

    public int countAllTasks() throws Exception {
        return 0;
    }

    public Task selTask(String taskId) throws Exception {
        return null;
    }

    public int updateTask(String taskId) throws Exception {
        return 0;
    }

    public int updateTask(Task task) throws Exception {
        return taskDao.updateTask(task);
    }

    @Override
    @Transactional
    public int updateTaskByStates(Map<String,Object> task) throws Exception {
        return taskDao.updateTaskByStates(task);
    }

    public int addTask(Task task) throws Exception {
        return 0;
    }

    public int deleteTask(String taskId) throws Exception {
        return 0;
    }
}
